<?php

class RssPostCategoryManager
{
    public static function GetTableName()
    {
        return Util::GetDatabaseTableName("rss_post_tag");
    }

    public static function InsertIds($postId, $categoryIds)
    {
        $tableName = self::GetTableName();
        $sql = "INSERT INTO $tableName (rss_post_id, rss_tag_id) VALUES ";
        $count = count($categoryIds);
        $postId = Util::Quote($postId);
        for ($i = 0; $i < $count; $i++)
        {
            $sql .= "(" . $postId . ", " . $categoryIds[$i] . ")";

            $isLast = ( $i == ($count - 1) );
            $sql .= ( !$isLast ) ? ", " : "";
        }
        Core::DBConn()->Query($sql);
    }

    public static function Insert($rssCategoryId, $rssPostId)
    {
        $tableName = self::GetTableName();
        $sql = "INSERT INTO $tableName
                    	(rss_post_id, rss_tag_id)
                    VALUE
                    	(@rss_post_id, @rss_tag_id)";

        $params = array
        (
        	'@rss_post_id' => $rssPostId,
            '@rss_tag_id' => $rssCategoryId
        );

        Core::DBConn()->Query($sql, Util::QuoteArray($params));
    }

    public static function DeletePostCategories($postId)
    {
        $sql = "DELETE FROM rss_post_tag WHERE rss_post_id = %s";
        Core::DBConn()->Query($sql, Util::Quote($postId));
    }

}

?>